<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>button</button>
    <script>
        let zh = {
            name:'张三', // 对象属性
            show:function(){ // 对象方法
                function render(){ // 普通函数
                    console.log(this); // this 指向window
                }
                render();
                return this.name; // this指向 zh对象
            }
        }
        console.log(zh.show());
        window.name = 'window的name属性';
        console.log(this.name)

        function User(){ // 构造函数
            this.name = name;
            this.show = function(){
                function render(){
                    console.log(this); // window
                }
                render();
                return this.name; // this指向的是window
            }
        }
        let user = new User('李思');
        console.log(user.show()); // window的name属性

        let Lesson = {
            site:"admin",
            lists:['js','html','css'],
            sh(){
                const self = this;
                return this.lists.map(function(item){
                    console.log(this.site); // undefined this指向window 
                    console.log(self.site); // admin
                })
            },
            mapFn(){
                return this.lists.map(function(){
                    console.log(this) // 通过map第二个参数改变this指向Lesson对象
                },this)
            },
            show(){
                return this.lists.map(item=>{ // 使用箭头函数解决this指向问题
                    console.log(this.site) // admin
                })
            }
        }
        Lesson.sh();
        Lesson.mapFn();
        Lesson.show();
        const btn = document.querySelector('button');
        btn.addEventListener('click',function(){
            console.log(this.innerHTML)
        })
    </script>
</body>
</html>